﻿using System;
using System.Windows.Data;
using System.Windows;

namespace OverlakeApp.Converters
{
    /// <summary>
    /// Converter that converts Boolean to visibility flag
    /// </summary>
    public class IsLoadingConverter : IValueConverter
    {
        /// <summary>
        /// Converts from a string to a string, but if the input is empty or null, returns "Loading..."
        /// </summary>
        /// <param name="value">The string to convert</param>
        /// <param name="targetType">Not implemented.</param>
        /// <param name="parameter">Not implemented</param>
        /// <param name="culture">Not implemented.</param>
        /// <returns>The input string, or "Loading..." if the input was empty or null.</returns>
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value != null && value is string && (value as string).Length != 0)
            {
                return value;
            }

            return "Loading...";
        }

        /// <summary>
        /// Not implemented.
        /// </summary>
        /// <param name="value"></param>
        /// <param name="targetType"></param>
        /// <param name="parameter"></param>
        /// <param name="culture"></param>
        /// <returns></returns>
        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return null;
        }
    }
}
